package com.pstreets.lwuit.demo.widgets;


import com.sun.lwuit.Command;
import com.sun.lwuit.Component;
import com.sun.lwuit.Display;
import com.sun.lwuit.Form;
import com.sun.lwuit.Image;
import com.sun.lwuit.Button;
import com.sun.lwuit.animations.CommonTransitions;
import com.sun.lwuit.events.ActionEvent;
import com.sun.lwuit.events.ActionListener;
import com.sun.lwuit.layouts.BoxLayout;
import com.sun.lwuit.plaf.UIManager;
import com.sun.lwuit.util.Resources;
import java.io.IOException;
import javax.microedition.midlet.MIDlet;

/**
 * @author james
 */
public class ButtonDemo extends MIDlet {

    public void startApp() {
        
        //init the LWUIT display
        Display.init(this);
        
        //setting the application theme
        try{
            Resources r=Resources.open("/LWUITtheme.res");
            UIManager.getInstance()
                    .setThemeProps(r.getTheme
                    (r.getThemeResourceNames()[0]));
        }catch (Exception e){}
        
        Form mainForm = new Form("Button Demo");
        mainForm.setLayout(new BoxLayout(BoxLayout.Y_AXIS));
        final Button button1=new Button("Text Only Button");
        button1.addActionListener(new ActionListener(){

            public void actionPerformed(ActionEvent ae) {
                button1.setText("New Text");
            }
        });
        
        mainForm.addComponent(button1);
        try {
            Image icon = Image.createImage("/navigator.png");
            Button button2=new Button(icon);
            mainForm.addComponent(button2);

            Button button3=new Button(icon);
            button3.setText("Image and Text Button");
            mainForm.addComponent(button3);
            
            Button button4=new Button(icon);
            button4.setText("Image and Text Button at Bottom");
            button4.setTextPosition(Component.BOTTOM);
            mainForm.addComponent(button4);
        } catch (IOException ex) {
            ex.printStackTrace();
        }
        
        

        mainForm.setTransitionOutAnimator(CommonTransitions.createFade(400));
        mainForm.addCommand(new Command("Left soft key", 2));
        mainForm.addCommand(new Command("Right Soft key", 2));
        mainForm.show();
        
    
    }
    
    public void pauseApp() {
    }
    
    public void destroyApp(boolean unconditional) {
    }
}
